package com.thx.user.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.thx.common.orm.model.ExtendPropertyEntity;
import com.thx.common.web.SessionInfo;
import com.thx.org.model.Department;
import com.thx.role.model.Role;

/**
 * 建立日期 : Jul 27, 2012 4:43:23 PM<br> 作者 : 贾红磊<br> 模块 : <br> 描述 : <br> 修改历史: 序号 日期 修改人 修改原因 <br> 1
 * <br> 2 <br>
 */
@Entity
@Table(name = "ORG_USER")
public class User extends ExtendPropertyEntity implements SessionInfo {

  private static final long serialVersionUID = -1519648255983983838L;

  @Id
  @GeneratedValue(generator = "generator")
  @GenericGenerator(name = "generator", strategy = "uuid")
  private String userId;
  private String userName;//登陆用户名
  private String realName;//真实姓名

  @Column(name = "sex_")
  private String sex;// 性别 0：男  1：女
  private String userLogo;//用户logo

  @Column(name = "email_")
  private String email;//邮箱
  private String mobilePhone;//手机号

  @Column(name = "password_")
  private String password;//密码
  private String pwdFormat;//加密方式

  @Column(name = "province_")
  private String province;// 所在省

  @Column(name = "city_")
  private String city;// 所在城市

  @Column(name = "region_")
  private String region;// 所在区县

  @Column(name = "approved_")
  private int approved;//是否审核通过
  private int lockedOut;//账号是否锁定
  private Date lastLockoutDate;//账号锁定时间

  @Column(name = "question_")
  private String question;//密码问题

  @Column(name = "answer_")
  private String answer;//问题答案
  private Date failedAnswerDate;//提醒问题回答错误时间
  private int failedAnswerCount;//提醒问题回答错误次数
  private Date failedDate;//登录失败时间
  private int failedCount;//登录失败次数
  private Date lastLoginDate;//最后一次登录时间
  private Date lastPwdChange;//密码最后一次更改时间
  private Date lastUpdateDate;//最后一次更改时间

  @Column(name = "creater_")
  private String creater;//创建人
  private Date createDate;//用户创建时间

  @Column(name = "modifier_")
  private String modifier;//密码修改人
  private Date modifyDate;//密码修改日期

  @ManyToMany(fetch = FetchType.LAZY)
  private Set<Role> roles = new HashSet<Role>();//关联角色
  private String postId;//职务ID

  @Transient
  private List<Role> roleList;

  @ManyToOne
  @JoinColumn(name = "deptId")
  private Department department;//所在部门
  private String comId;//企业id

  @Column(name = "status_")
  private String status;//状态 0：已删   1:未删    2：暂停

  @Column(name = "imsi_")
  private String imsi;//sim卡序列号
  private String deviceId;//设备号
  private String accessPermit = "all";//用户访问许可，all|web|mobile

  @Column(name = "remark_")
  private String remark;// 备注

  private String salt;//盐（密码安全）

  @Column(name = "reserve_1")
  private String reserve1;

  @Column(name = "reserve_2")
  private String reserve2;

  @Column(name = "reserve_3")
  private String reserve3;

  @Column(name = "reserve_4")
  private String reserve4;

  @Column(name = "reserve_5")
  private String reserve5;

  @Column(name = "reserve_6")
  private String reserve6;

  @Column(name = "reserve_7")
  private String reserve7;

  @Column(name = "reserve_8")
  private String reserve8;

  @Column(name = "reserve_9")
  private String reserve9;

  @Column(name = "reserve_10")
  private String reserve10;

  public void addRoles(Role role) {
    this.roles.add(role);
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((userId == null) ? 0 : userId.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    User other = (User) obj;
    if (userId == null) {
      if (other.userId != null) {
        return false;
      }
    } else if (!userId.equals(other.userId)) {
      return false;
    }
    return true;
  }

	/*set get method*/

  public String getUserId() {
    return userId;
  }

  public void setUserId(String userId) {
    this.userId = userId;
  }

  public String getUserName() {
    return userName;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public String getRealName() {
    return realName;
  }

  public void setRealName(String realName) {
    this.realName = realName;
  }

  public String getSex() {
    return sex;
  }

  public void setSex(String sex) {
    this.sex = sex;
  }

  public String getUserLogo() {
    return userLogo;
  }

  public void setUserLogo(String userLogo) {
    this.userLogo = userLogo;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getMobilePhone() {
    return mobilePhone;
  }

  public void setMobilePhone(String mobilePhone) {
    this.mobilePhone = mobilePhone;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getPwdFormat() {
    return pwdFormat;
  }

  public void setPwdFormat(String pwdFormat) {
    this.pwdFormat = pwdFormat;
  }

  public String getProvince() {
    return province;
  }

  public void setProvince(String province) {
    this.province = province;
  }

  public String getCity() {
    return city;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public String getRegion() {
    return region;
  }

  public void setRegion(String region) {
    this.region = region;
  }

  public int getApproved() {
    return approved;
  }

  public void setApproved(int approved) {
    this.approved = approved;
  }

  public int getLockedOut() {
    return lockedOut;
  }

  public void setLockedOut(int lockedOut) {
    this.lockedOut = lockedOut;
  }

  public Date getLastLockoutDate() {
    return lastLockoutDate;
  }

  public void setLastLockoutDate(Date lastLockoutDate) {
    this.lastLockoutDate = lastLockoutDate;
  }

  public String getQuestion() {
    return question;
  }

  public void setQuestion(String question) {
    this.question = question;
  }

  public String getAnswer() {
    return answer;
  }

  public void setAnswer(String answer) {
    this.answer = answer;
  }

  public Date getFailedAnswerDate() {
    return failedAnswerDate;
  }

  public void setFailedAnswerDate(Date failedAnswerDate) {
    this.failedAnswerDate = failedAnswerDate;
  }

  public int getFailedAnswerCount() {
    return failedAnswerCount;
  }

  public void setFailedAnswerCount(int failedAnswerCount) {
    this.failedAnswerCount = failedAnswerCount;
  }

  public Date getFailedDate() {
    return failedDate;
  }

  public void setFailedDate(Date failedDate) {
    this.failedDate = failedDate;
  }

  public int getFailedCount() {
    return failedCount;
  }

  public void setFailedCount(int failedCount) {
    this.failedCount = failedCount;
  }

  public Date getLastLoginDate() {
    return lastLoginDate;
  }

  public void setLastLoginDate(Date lastLoginDate) {
    this.lastLoginDate = lastLoginDate;
  }

  public Date getLastPwdChange() {
    return lastPwdChange;
  }

  public void setLastPwdChange(Date lastPwdChange) {
    this.lastPwdChange = lastPwdChange;
  }

  public Date getLastUpdateDate() {
    return lastUpdateDate;
  }

  public void setLastUpdateDate(Date lastUpdateDate) {
    this.lastUpdateDate = lastUpdateDate;
  }

  public String getCreater() {
    return creater;
  }

  public void setCreater(String creater) {
    this.creater = creater;
  }

  public Date getCreateDate() {
    return createDate;
  }

  public void setCreateDate(Date createDate) {
    this.createDate = createDate;
  }

  public String getModifier() {
    return modifier;
  }

  public void setModifier(String modifier) {
    this.modifier = modifier;
  }

  public Date getModifyDate() {
    return modifyDate;
  }

  public void setModifyDate(Date modifyDate) {
    this.modifyDate = modifyDate;
  }

  public Set<Role> getRoles() {
    return roles;
  }

  public void setRoles(Set<Role> roles) {
    this.roles = roles;
  }

  public String getPostId() {
    return postId;
  }

  public void setPostId(String postId) {
    this.postId = postId;
  }

  public Department getDepartment() {
    return department;
  }

  public void setDepartment(Department department) {
    this.department = department;
  }

  public String getComId() {
    return comId;
  }

  public void setComId(String comId) {
    this.comId = comId;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public String getImsi() {
    return imsi;
  }

  public void setImsi(String imsi) {
    this.imsi = imsi;
  }

  public String getDeviceId() {
    return deviceId;
  }

  public void setDeviceId(String deviceId) {
    this.deviceId = deviceId;
  }

  public String getAccessPermit() {
    return accessPermit;
  }

  public void setAccessPermit(String accessPermit) {
    this.accessPermit = accessPermit;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public String getReserve1() {
    return reserve1;
  }

  public void setReserve1(String reserve1) {
    this.reserve1 = reserve1;
  }

  public String getReserve2() {
    return reserve2;
  }

  public void setReserve2(String reserve2) {
    this.reserve2 = reserve2;
  }

  public String getReserve3() {
    return reserve3;
  }

  public void setReserve3(String reserve3) {
    this.reserve3 = reserve3;
  }

  public String getReserve4() {
    return reserve4;
  }

  public void setReserve4(String reserve4) {
    this.reserve4 = reserve4;
  }

  public String getReserve5() {
    return reserve5;
  }

  public void setReserve5(String reserve5) {
    this.reserve5 = reserve5;
  }

  public String getReserve6() {
    return reserve6;
  }

  public void setReserve6(String reserve6) {
    this.reserve6 = reserve6;
  }

  public String getReserve7() {
    return reserve7;
  }

  public void setReserve7(String reserve7) {
    this.reserve7 = reserve7;
  }

  public String getReserve8() {
    return reserve8;
  }

  public void setReserve8(String reserve8) {
    this.reserve8 = reserve8;
  }

  public String getReserve9() {
    return reserve9;
  }

  public void setReserve9(String reserve9) {
    this.reserve9 = reserve9;
  }

  public String getReserve10() {
    return reserve10;
  }

  public void setReserve10(String reserve10) {
    this.reserve10 = reserve10;
  }

  public String getSalt() {
    return salt;
  }

  public void setSalt(String salt) {
    this.salt = salt;
  }

  @Override
  public Serializable getId() {
    return this.userId;
  }

  public List<Role> getRoleList() {
    return roleList;
  }

  public void setRoleList(List<Role> roleList) {
    this.roleList = roleList;
  }
}
